//
//  ZDOrderDetailCell.m
//  特种车调度
//
//  Created by 陈宇 on 15/8/23.
//
//

#import "ZDOrderDetailCell.h"
#import "BMStarView.h"

@interface ZDOrderDetailCell ()

@property (weak, nonatomic) IBOutlet UIImageView *logoView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *carLabel;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *workStatusView;
@property (weak, nonatomic) IBOutlet BMStarView *starView;

@end

@implementation ZDOrderDetailCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (IBAction)callAction:(id)sender {
    [BMUtils callWithPhoneNumber:_log.phone];
}

- (void)setLog:(OrderLog *)log
{
    _log = log;
    
    [self.logoView sd_setImageWithURL:[NSURL URLWithString:_log.icon]];
    self.titleLabel.text = _log.driver;
    self.carLabel.text = [_log.licensePlate stringByAppendingString:_log.licensePlateNum];
    self.infoLabel.text = [NSString stringWithFormat:@"%@:%@", _log.style1, _log.styleName ? _log.styleName : @""];
    self.starView.level = log.averageScore;
    
    ZDOwnerStatus ownerStatus = log.statusId;
    
    //设置订单取消及其与背景
    switch (ownerStatus) {
        case ZDOwnerStatusClose:
        case ZDOwnerStatusCancel:
        case ZDOwnerStatusCancel1:
        case ZDOwnerStatusCancel2:
        case ZDOwnerStatusRepeal:
            self.bgView.backgroundColor = [UIColor lightGrayColor];
            break;
        default:
            self.bgView.backgroundColor = kGlobalColor;
            break;
    }
    
    //设置订单取消和改派状态
    switch (ownerStatus) {
        case ZDOwnerStatusCancel:
        case ZDOwnerStatusCancel1:
        case ZDOwnerStatusCancel2:
            self.workStatusView.hidden = NO;
            self.workStatusView.image = [UIImage imageNamed:@"status_order_0"];
            break;
        case ZDOwnerStatusGP:
            self.workStatusView.hidden = NO;
            self.workStatusView.image = [UIImage imageNamed:@"status_order_1"];
            break;
        default:
            self.workStatusView.hidden = YES;
            break;
    }
    
    if (_log.statusId == ZDOwnerStatusClose) {
        self.userInteractionEnabled = NO;
    } else {
        self.userInteractionEnabled = YES;
    }
}

@end
